/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.cast.teseg.gui;

import edu.cast.teseg.controladores.Controlador;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 *
 * @author edgarin
 */
public class ManejoEventos implements MouseListener,ChangeListener{
    GuiPrincipal guiGL;
    Controlador controlGL;

    public ManejoEventos(){}

    public void setControlador(Controlador x){ this.controlGL = x; }

    public void setGuiPrincipal(GuiPrincipal x){ this.guiGL = x; }

    //*** metodo para agregar listener a los componentes GUI ***//
    @Override
    public void mouseClicked(MouseEvent e) {
        
        if(e.getSource() == this.guiGL.getSubirArchivos()){
            this.controlGL.subirArchivos();
        }
        else if(e.getSource() == this.guiGL.getGenerarBtn()){
            if(!this.controlGL.isNumeric(this.guiGL.numNodos.getText())){
                this.controlGL.setMensajeErrores("Vertice no numerico o no entero");
            }
            else if(!this.controlGL.isNumeric(this.guiGL.contProb.getText().replaceAll("\\.", ""))){
                this.controlGL.setMensajeErrores("error en el archivo un dato no es numero");
            }
            
            this.controlGL.iniciarGraficoGrafo(Integer.parseInt(this.guiGL.getNumNodos().getText()),Double.parseDouble(this.guiGL.getContProb().getText()));
          //  this.controlGL.setGraficoGrafo();
        }        
        else if(e.getSource() == this.guiGL.getDetenerBtn()){
            
        }
        else if(e.getSource() == this.guiGL.getBorrarDatos()){
            
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {}

    @Override
    public void mouseReleased(MouseEvent e) {}

    @Override
    public void mouseEntered(MouseEvent e) {}

    @Override
    public void mouseExited(MouseEvent e) {}

    //*** metodo para agregar listener la barra deslizadora ***//
    @Override
    public void stateChanged(ChangeEvent e) {
        if(e.getSource() == this.guiGL.getBarraProb()){
            this.guiGL.getContProb().setText(Double.toString(((JSlider)e.getSource()).getValue()/100.));
            this.controlGL.iniciarGraficoGrafo(Integer.parseInt(this.guiGL.getNumNodos().getText()),Double.parseDouble(this.guiGL.getContProb().getText()));
        }        
    }

}